#pragma  once
#ifndef dx_H__
#define dx_H__

#define myTrace0A(level,msg)					xTrace0A(eType_OutConsol,level,msg)
#define myTrace1A(level,msg,msgArg)				xTrace1A(eType_OutConsol,level,msg,msgArg)
#define myTrace2A(level,msg,msgArg1,msgArg2)	xTrace2A(eType_OutConsol,level,msg,msgArg1,msgArg2)

#define myTrace0W(level,msg)					xTrace0W(eType_OutConsol,level,msg)
#define myTrace1W(level,msg,msgArg)				xTrace1W(eType_OutConsol,level,msg,msgArg)
#define myTrace2W(level,msg,msgArg1,msgArg2)	xTrace2W(eType_OutConsol,level,msg,msgArg1,msgArg2)

#define myDe_Trace_hr0(level,hr,msg)			xTraceHr0A(eType_OutConsol,level,hr,""#msg)
#define myDx_Trace_hr0(level,hr,msg)			xTraceHr0A(eType_OutConsol,level,hr,""#msg)
#define myDi_Trace_hr0(level,hr,msg)			xTraceHr0A(eType_OutConsol,level,hr,""#msg)
#define myWin_Trace_hr0(level,hr,msg)			xTraceHr0A(eType_OutConsol,level,hr,""#msg)

#define myDx_Trace_hr1(level,hr,msg,arg)		xTraceHr1A(eType_OutConsol,level,hr,""#msg,arg)
#define myDx_Trace_hr2(level,hr,msg,arg1,arg2)  xTraceHr2A(eType_OutConsol,level,hr,""#msg,arg1,arg2)

#define myDeV(fun,level)				{TResult myhr = fun;if(FAILED(myhr)){myDe_Trace_hr0(level,myhr,fun);}}
#define myDxV(fun,level)				{TResult dxhr = fun;if(FAILED(dxhr)){myDx_Trace_hr0(level,dxhr,fun);}}
#define myDiV(fun,level)				{TResult dihr = fun;if(FAILED(dihr)){myDi_Trace_hr0(level,dihr,fun);}}
#define myWinV(fun,level)				{TResult winhr = fun;if(FAILED(winhr)){myWin_Trace_hr0(level,winhr,fun);}}

#define myDeV_M(fun)	myDeV(fun,E)
#define myDxV_M(fun)	myDxV(fun,E)
#define myDiV_M(fun)	myDiV(fun,E)
#define myWinV_M(fun)	myWinV(fun,E)

#define myDeV_Ret(fun,level)		{TResult myhr = fun;if(FAILED(myhr)){return myDe_Trace_hr0(level,myhr,fun);}}
#define myDxV_Ret(fun,level)		{TResult dxhr = fun;if(FAILED(dxhr)){return myDx_Trace_hr0(level,dxhr,fun);}}
#define myDiV_Ret(fun,level)		{TResult dihr = fun;if(FAILED(dihr)){return myDi_Trace_hr0(level,dihr,fun);}}
#define myWinV_Ret(fun,level)		{TResult winhr = fun;if(FAILED(winhr)){return myWin_Trace_hr0(level,winhr,fun);}}

#define myDeV_Ret_M(fun)			myDeV_Ret(fun,E)
#define myDxV_Ret_M(fun)			myDxV_Ret(fun,E)
#define myDiV_Ret_M(fun)			myDiV_Ret(fun,E)
#define myWinV_Ret_M(fun)			myWinV_Ret(fun,E)

#define myN_Ret(ptr,fun,hr,level)		{ptr = fun;if(ptr == vNull){myTrace0(level,##L#fun##_XT(" return vNull"));return hr;}}
#define myN_Ret_hr_M(ptr,fun,hr)		myN_Ret(ptr,fun,hr,E)

#define myDeV_Ret_hr(fun,hr,level)		{TResult myhr = fun;if(FAILED(myhr)){myDe_Trace_hr0(level,myhr,fun);return hr;}}
#define myDxV_Ret_hr(fun,hr,level)		{TResult dxhr = fun;if(FAILED(dxhr)){myDx_Trace_hr0(level,dxhr,fun);return hr;}}
#define myDiV_Ret_hr(fun,hr,level)		{TResult dihr = fun;if(FAILED(dihr)){myDi_Trace_hr0(level,dihr,fun);return hr;}}
#define myWinV_Ret_hr(fun,hr,level)		{TResult winhr = fun;if(FAILED(winhr)){myWin_Trace_hr0(level,winhr,fun);return hr;}}

#define myDeV_Ret_hr_M(fun,hr)			myDeV_Ret_hr(fun,hr,E)
#define myDxV_Ret_hr_M(fun,hr)			myDxV_Ret_hr(fun,hr,E)
#define myDiV_Ret_hr_M(fun,hr)			myDiV_Ret_hr(fun,hr,E)
#define myWinV_Ret_hr_M(fun,hr)			myWinV_Ret_hr(fun,hr,E)

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=vNull; } }
#endif    
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=vNull; } }
#endif    
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=vNull; } }
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a)		(sizeof(a)/sizeof(a[0]))
#endif

#ifndef XSUCCEEDED
#define XSUCCEEDED(hr)		((TResult)(hr) >= 0)
#endif

#ifndef XFAILED
#define XFAILED(hr)			((TResult)(hr) < 0)
#endif

#ifdef __cplusplus
#ifndef XEXTERN_C
#define XEXTERN_C	extern	"C"
#endif
#else
#define XEXTERN_C	extern
#endif

#endif // dx_H__